﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace CIS.Server.Repository
{
    public interface IBaseRepository<T> where T : class, new()
    {
        #region 添加操作
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<bool> AddAsync(T entity);

        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<bool> AddManyAsync(List<T> entities);
        #endregion

        #region 查询操作
        /// <summary>
        /// 根据条件查询数据是否存在
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        Task<bool> AnyAsync(Expression<Func<T, bool>> where);

        /// <summary>
        /// 根据条件合计字段
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="where"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field);

        /// <summary>
        /// 根据主键查询单条数据
        /// </summary>
        /// <param name="pkValue">主键值</param>
        /// <returns></returns>
        Task<T> GetByIdAsync(object pkValue);

        /// <summary>
        /// 根据主键查询多条数据
        /// </summary>
        /// <returns></returns>
        Task<List<T>>? GetManyAsync(Func<T,bool> where);

        /// <summary>
        /// 根据条件获取条数
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        Task<int> GetCountAsync(Expression<Func<T, bool>> where);

        /// <summary>
        /// 查询所有数据（无分页，请慎用）
        /// </summary>
        /// <param name="useCache"></param>
        /// <param name="cacheSecond"></param>
        /// <returns></returns>
        Task<List<T>> GetAllAsync(bool useCache = false, int cacheSecond = 3600);

        /// <summary>
        /// 获得一条数据
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        Task<T> GetFirst(Expression<Func<T, bool>> where);

        /// <summary>
        /// 获得一条数据
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        Task<T> GetFirst(string parm);

        ///// <summary>
        ///// 根据条件查询分页数据
        ///// </summary>
        ///// <param name="where"></param>
        ///// <param name="parm"></param>
        ///// <returns></returns>
        //PagedInfo<T> GetPages(Expression<Func<T, bool>> where,PageParm parm);
        #endregion

        #region MyRegion

        #endregion

        #region MyRegion

        #endregion

        #region MyRegion

        #endregion
    }
}
